<?php

namespace App\Services;

use App\Models\PreDzlabQwenPack;
use Slowlyo\OwlAdmin\Services\AdminService;

/**
 * 套餐记录
 *
 * @method PreDzlabQwenPack getModel()
 * @method PreDzlabQwenPack|\Illuminate\Database\Query\Builder query()
 */
class PreDzlabQwenPackService extends AdminService
{
	protected string $modelName = PreDzlabQwenPack::class;

	public function sortable($query)
	{
		if (request()->orderBy && request()->orderDir) {
			$query->orderBy(request()->orderBy, request()->orderDir ?? 'asc');
		} else {
			$query->orderByDesc('id');
		}
	}

	public function searchable($query)
	{
		parent::searchable($query);
		$query->when(filled(request('username')), function ($query) {
			$query->whereHas('user', function ($query) {
				$query->where('username', 'like', '%' . request('username') . '%');
			});
		});
	}
}
